using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using System.Xml;
using Winsmarts.PPI.Common;

namespace ProfilePropertyMgr
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramInputs inputs = new ProgramInputs(args);

            if (inputs.IsValid)
            {
                try
                {
            using (SPSite site = new SPSite(inputs.Url))
            {
                ServerContext context = ServerContext.GetContext(site);
                UserProfileManager profileManager = new UserProfileManager(context);

                switch (inputs.CurrentOperation)
                {
                    case Operation.Unspecified:
                        throw new InvalidOperationException("Invalid input operation specified, or input operation omitted, cannot continue");
                    case Operation.Import:
                        WorkerBee.ImportProfiles(inputs, profileManager);
                        break;
                    case Operation.Export:
                        WorkerBee.ExportProfiles(inputs, profileManager);
                        break;
                    default: // This will never happen, so safely ignored.
                        break;
                }
            }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unexpected error occurred:", true);
                    Trace.WriteLine(ex.ToString(), true);
                }
            }
            else
            {
                Trace.WriteLine("Invalid inputs specified", true);
                Trace.PrintHelp();
            }
        }
    }
}